package com.yuda.afterexamscore.controller;

import com.yuda.afterexamscore.domain.ThQuesScoreMapping;
import com.yuda.afterexamscore.domain.ThQuesTypeAnalysis;
import com.yuda.afterexamscore.service.IThQuesScoreMappingService;
import com.yuda.afterexamscore.vo.ThQuesScoreMappingVo;
import com.yuda.common.core.utils.poi.ExcelUtil;
import com.yuda.common.core.web.controller.BaseController;
import com.yuda.common.core.web.domain.AjaxResult;
import com.yuda.common.core.web.page.TableDataInfo;
import com.yuda.common.log.annotation.Log;
import com.yuda.common.log.enums.BusinessType;
import com.yuda.common.security.annotation.PreAuthorize;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * 【请填写功能名称】Controller
 *
 * @author wyn
 * @date 2021-05-12
 */
@RestController
@RequestMapping("/thQuesScoreMapping")
@RefreshScope
public class ThQuesScoreMappingController extends BaseController
{
    @Autowired
    private IThQuesScoreMappingService thQuesScoreMappingService;

    /**
     * 查询【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "afterexamscore:mapping:list")
    @GetMapping("/list")
    public TableDataInfo list(ThQuesScoreMapping thQuesScoreMapping)
    {
        startPage();
        List<ThQuesScoreMapping> list = thQuesScoreMappingService.selectThQuesScoreMappingList(thQuesScoreMapping);
        return getDataTable(list);
    }

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize(hasPermi = "afterexamscore:mapping:list")
    @ApiOperation("填空题学生答案穷举列表")
    @GetMapping("/tianKongList")
    public TableDataInfo tianKongList(@ApiParam(value = "穷举表信息", required = true)ThQuesScoreMapping thQuesScoreMapping)
    {
        startPage();
        List<ThQuesScoreMappingVo> list = thQuesScoreMappingService.queryTianKongList(thQuesScoreMapping);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @PreAuthorize(hasPermi = "afterexamscore:mapping:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ThQuesScoreMapping thQuesScoreMapping) throws IOException
    {
        List<ThQuesScoreMapping> list = thQuesScoreMappingService.selectThQuesScoreMappingList(thQuesScoreMapping);
        ExcelUtil<ThQuesScoreMapping> util = new ExcelUtil<ThQuesScoreMapping>(ThQuesScoreMapping.class);
        util.exportExcel(response, list, "mapping");
    }

//    @PostMapping("/import")
//    public void importExcel(MultipartFile multipartFile) throws Exception {
//        InputStream inputStream = multipartFile.getInputStream();
//        ExcelUtil<ThQuesScoreMapping> excelUtil = new ExcelUtil<>(ThQuesScoreMapping.class);
//        List<ThQuesScoreMapping> list = excelUtil.importExcel("sheet2", inputStream);
//        thQuesScoreMappingService.batchInsertThQuesScoreMapping(list);
//    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @PreAuthorize(hasPermi = "afterexamscore:mapping:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(thQuesScoreMappingService.selectThQuesScoreMappingById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @PreAuthorize(hasPermi = "afterexamscore:mapping:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ThQuesScoreMapping thQuesScoreMapping)
    {
        return toAjax(thQuesScoreMappingService.insertThQuesScoreMapping(thQuesScoreMapping));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize(hasPermi = "afterexamscore:mapping:edit")
    @Log(title = "修改填空题答案分数", businessType = BusinessType.UPDATE)
    @ApiOperation("修改答案分数,传入id,score即可")
    @PutMapping
    public AjaxResult edit(@RequestBody ThQuesScoreMapping thQuesScoreMapping)
    {
        return toAjax(thQuesScoreMappingService.updateThQuesScoreMapping(thQuesScoreMapping));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize(hasPermi = "afterexamscore:mapping:remove")
    @Log(title = "删除填空题答案", businessType = BusinessType.DELETE)
    @ApiOperation("批量删除")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(thQuesScoreMappingService.deleteThQuesScoreMappingByIds(ids));
    }
}
